﻿using System;
using System.Collections.Generic;
using Token.Piker.Common;

namespace Token.Piker.Web
{
    public partial class SingleByPID : Piker.Core.PikerBasePage
    {
        public static int startIndex = 0;
        public static int PicNum = 0; //用户上传图片总数
        //相册拥有者信息
        public static string userName = "";
        public static string userPic = "";
        //评论者信息（在线用户）
        public static string puserName = "";
        public static string puserPic = "";
        public static int UID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                int UserID = Session[GlobalConstants.PIKER_USER_ID] == null ? 0 : Int32.Parse(Session[GlobalConstants.PIKER_USER_ID].ToString().Trim());//当前在线用户
                string PID = (Request.QueryString["PID"] == null || Request.QueryString["PID"] == "") ? "0" : Request.QueryString["PID"];//通过上传者找图片
                //string PID = "21";
                if (PID != null && PID.ToString() != "")
                {
                    Token.Piker.BLL.PhotoBLL singleBll = new Token.Piker.BLL.PhotoBLL();
                    Model.Photo photo = new Model.Photo();
                    photo = singleBll.GetModel(int.Parse(PID));
                    //相册拥有者信息
                    UID = photo.UserID;
                    Token.Piker.Model.User user = GetUser(photo.UserID.ToString());
                    userName = user.UserName;
                    userPic = user.UserPic;
                    //评论者信息（在线用户）
                    Token.Piker.Model.User puser = GetUser(UserID.ToString());
                    puserName = puser.UserName;
                    puserPic = puser.UserPic;
                    //绑定图片数据
                    PicNum = 1;
                    List<Model.Photo> listPhoto = new List<Model.Photo>();
                    listPhoto.Add(photo);
                    Single_pic.DataSource = listPhoto;// picNum >= 12 ? singleBll.GetListByPage(string.Format(" UserID= {0} ", UID.ToString()), "ID", 1, 12) : singleBll.GetListByPage(string.Format(" UserID= {0} ", UID), "ID", 1, picNum);
                }
                else
                {
                    Single_pic.DataSource = null;
                }
                Single_pic.DataBind();
            }
            else
            {
            }

        }

        public string GetUserName(string UID)
        {
            Token.Piker.Model.User pikerUser = new Token.Piker.Model.User();
            if (UID != "0")
            {
                //绑定用户名
                Token.Piker.BLL.UserBLL Userbll = new Token.Piker.BLL.UserBLL();
                pikerUser = Userbll.GetModel(Int32.Parse(UID.ToString()));
            }
            else
            {
                pikerUser = new Token.Piker.Model.User();
            }
            return pikerUser == null ? "游客" : pikerUser.UserName;
        }

        public Token.Piker.Model.User GetUser(string UID)
        {
            if (UID == "0")
            {
                Token.Piker.Model.User pUser = new Token.Piker.Model.User();
                pUser.UserName = "游客";
                pUser.UserPic = "../Images/youke.jpg";
                return pUser;
            }
            //绑定用户名
            Token.Piker.BLL.UserBLL Userbll = new Token.Piker.BLL.UserBLL();
            Token.Piker.Model.User pikerUser = new Token.Piker.Model.User();
            pikerUser = Userbll.GetModel(Int32.Parse(UID.ToString()));
            if (pikerUser == null || pikerUser.UserName == null)
            {
                pikerUser = new Token.Piker.Model.User();
                pikerUser.UserName = "游客";
                pikerUser.UserPic = "../Images/youke.jpg";
            }
            return pikerUser;
        }
    }
}